package cn.aloxc.stock.context.data
import cn.aloxc.stock.fund.*;
import java.util.ArrayList;
import java.util.Date;
import groovy.sql.*;
import cn.aloxc.stock.context.SysContext;
public class ManageData
{
		def sql;
		public static void main(def args){

			def instance = new ManageData();
			instance.initConn();
            def ids = instance.checkZcgg();

		}
	def checkZcgg()
	{
		def tbName = "zcggstat";
		def tbcheck = "mycounter";
		def sid = 0;
		def maxId = 0;
        def minId = 0;
        def oldData = new ArrayList(),reoldData = new ArrayList(),newData = new ArrayList();
              Map map = new HashMap();


      
		sql.eachRow("select * from rezcggstat  order by id asc"){
                     def val = [it.code,it.name,it.days,it.fund,it.qujianbi,it.liutongbi,it.swap,it.range,it.time,it.statdate,it.atype,it.starttime,it.endtime];

	                sid = it.starttime+it.code+it.atype;
          map.put(sid,val);
          //println sid
                     //println "${it.id}:${it.name}"
	              }
               println map.size()
       // System.out.println(keys1);
             map.each{ 
               //println it.key + it.value[1];
               def v = it.value;
               sql.executeInsert("insert into okzcggstat(code,name,days,fund,qujianbi,liutongbi,swap,range,time,statdate,atype,starttime,endtime)" +
                                   "values(?,?,?,?,?,?,?,?,?,?,?,?,?)",[v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12]])

             }
    println sid
    println maxId
      
	}
		private void initConn()
		{

			def driver = "com.mysql.jdbc.Driver";
			def db = "jdbc:mysql://localhost/stockstat?useUnicode=true&characterEncoding=gb2312";
			def user = "root";
			def pwd = "111111";
			sql = Sql.newInstance(db,user,pwd,driver);

		}
		def insert_a(def p)
		{

			p = (HexunFund)p;

	        def sdf=new java.text.SimpleDateFormat("yyyy-MM-dd");
			sql.executeInsert("insert into fundstat(rank,code,name,fund,percent,atype,period,statdate)" +
					"values(?,?,?,?,?,?,?,?)",[p.rank,p.code,p.name,p.fund,p.percent,p.atype,p.period,sdf.format(p.statdate)])

		}
}
